home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 #1 / Ham Radio 2000.iso / ham2000 / tcp_ip / tnos / tnos100s / sccvec.asm < prev    next >
Encoding:
Assembly Source File  |  1993-07-09  |  7.4 KB  |  251 lines

  1. ; Modified from the PE1CHL version to work with NOS.
  2. ; This file cannot be used with the PE1CHL sources.
  3. ; 1/21/90
  4. ; Ken Mitchum, KY3B   km@speedy.cs.pitt.edu km@cadre.dsl.pitt.edu
  5. ; SCC interrupt handler for IBM-PC
  6.  
  7. ;   
  8.  
  9.  
  10. include asmglobal.h        
  11.     LOCALS
  12.     %MACS
  13.     .LALL
  14.  
  15.     extrn   Stktop,Spsave,Sssave,doret:proc,scctim:proc,eoi:proc
  16.     extrn   porg:proc
  17.     extrn   Sccvecloc,Sccpolltab,Sccmaxvec:byte
  18.  
  19. ifdef   LARGEDATA
  20.     extrn   Sccchan:dword
  21. else
  22.     extrn   Sccchan:word
  23. endif
  24.     
  25.     .CODE
  26. dbase   dw      @Data           ; save loc for ds (must be in code segment)
  27.  
  28. ; sccvec is the interrupt handler for SCC interrupts using INTACK
  29.  
  30.     public sccvec
  31.     label   sccvec  far
  32.  
  33.     cli                     ; this code is not re-entrant, so make sure it
  34.                 ; is not interrupted. some multi-taskers
  35.                 ; intercept interrupt handlers, so be careful!
  36.  
  37.  
  38.     push    ds              ; save on user stack
  39.  
  40.     mov     ds,cs:dbase
  41.  
  42.     mov     Sssave,ss       ; stash user stack context
  43.     mov     Spsave,sp
  44.  
  45.     mov     ss,cs:dbase             ; set up interrupt stack
  46.     lea     sp,Stktop
  47.  
  48.       ;  push    ax              ; save user regs on interrupt stack
  49.       ;  push    bx
  50.       ;  push    cx
  51.       ;  push    dx
  52.       ;  push    bp
  53.       ;  push    si
  54.       ;  push    di
  55.     PUSHALL
  56.     push    es
  57.     call    eoi
  58. ifndef  LARGEDATA
  59.     mov     es,ax           ; small data assumes ES == DS
  60. endif
  61.     cld                     ; in case "movsb" or "movsw" is used
  62.  
  63.  
  64. ; Read SCC interrupt vector and check it
  65.  
  66. sccint: mov     dx,Sccvecloc
  67.     out     dx,al                   ; Generate INTACK
  68.     jmp     short d1                ; Delay
  69. d1:     jmp     short d2
  70. d2:     jmp     short d3
  71. d3:     in      al,dx                   ; Read the vector
  72.     cmp     al,Sccmaxvec            ; Check for a legal vector
  73.     jnc     clrret                  ; It should not be >= the maximum
  74.                     ; If it is, ignore the interrupt
  75.  
  76. ; Extract channel number and status from vector. Determine handler address.
  77.  
  78.     mov     bl,al                   ; Copy vector (need it later for status)
  79.     shr     bl,1                    ; Discard least significant bit
  80.     jc      clrret                  ; It should not be a 1
  81.     and     bx,7ch                  ; Isolate channel number (and make word)
  82.     xor     bl,04h                  ; Toggle A/B channel bit
  83. ifdef   LARGEDATA
  84.     les     si,Sccchan[bx]  ; Read address of channel structure
  85. else
  86.     shr     bl,1                    ; Discard another bit
  87.     mov     si,Sccchan[bx]          ; Read address of channel structure
  88. endif
  89. ifdef   LARGEDATA               ; Test for NULL
  90.     push    ax
  91.     mov             ax,es
  92.     test    ax,ax
  93.     pop             ax
  94.     jne     nn0
  95. endif
  96.     test    si,si                   ; Test for NULL
  97.     je      clrret                  ; No channel struct, ignore it
  98. nn0:
  99.     and     ax,06h                  ; Isolate status info from vector
  100.     add     ax,ax                   ; Make index in FAR PTR array
  101.     mov     bx,ax                   ; It must be in BX
  102.  
  103. ; Call the handler (defined in C), with Sccchan struct as a parameter
  104.  
  105.     push    es
  106.     push    si                      ; Put channel struct as a parameter
  107. ifdef   LARGEDATA
  108.     call    dword ptr es:[bx+si]    ; Call the handler
  109. else
  110.     call    dword ptr [bx+si]       ; Call the handler
  111. endif
  112.     pop     si                      ; Get channel struct back
  113.     pop     es
  114.  
  115. ; Reset highest priority interrupt
  116.  
  117. ifdef   LARGEDATA
  118.     mov     dx,es:16[si]            ; Get control register address
  119. else
  120.     mov     dx,16[si]               ; Get control register address
  121. endif
  122.     mov     al,38h                  ; "Reset Highest IUS" opcode
  123.     out     dx,al                   ; to WR0
  124.     jmp     short d4        ; settling delay
  125. d4:     jmp     short d5
  126. d5:
  127.  
  128. ; Determine if more interrupt requests are coming in from the SCCs
  129.  
  130.     jmp     sccint                  ; keep trying until no vector returned
  131.  
  132. ; Clear the ISR bit in the PIC and return from interrupt
  133.  
  134. clrret: 
  135.         jmp     doret                   ; execute code in pcint.asm
  136.  
  137. ;       sccvec  endproc
  138.  
  139. ; sccnovec is the interrupt handler for SCC interrupts using polling
  140.  
  141.     public sccnovec
  142.     label sccnovec far
  143.     
  144.     cli                     ; this code is not re-entrant, so make sure it
  145.                 ; is not interrupted. some multi-taskers
  146.                 ; intercept interrupt handlers, so be careful!
  147.  
  148.  
  149.     push    ds              ; save on user stack
  150.     mov     ds,cs:dbase
  151.  
  152.     mov     Sssave,ss       ; stash user stack context
  153.     mov     Spsave,sp
  154.  
  155.     mov     ss,cs:dbase             ; set up interrupt stack
  156.     lea     sp,Stktop
  157.  
  158.     ; push    ax              ; save user regs on interrupt stack
  159.     ; push    bx
  160.     ; push    cx
  161.     ; push    dx
  162.     ; push    bp
  163.     ; push    si
  164.     ; push    di
  165.     PUSHALL
  166.     push    es
  167.     call    eoi
  168. ifndef  LARGEDATA
  169.     mov     es,ax           ; small data assumes ES == DS
  170. endif
  171.  
  172.     cld                     ; in case "movsb" or "movsw" is used
  173.  
  174.  
  175. ; Find the SCC generating the interrupt by polling all attached SCCs
  176. ; reading RR3A (the interrupt pending register)
  177.  
  178. sccintnv:
  179.     lea     si,Sccpolltab           ; Point to polling table
  180. sccpoll:
  181.     mov     dx,[si]                 ; Get chan A CTRL address
  182.     inc     si
  183.     inc     si
  184.     test    dx,dx                   ; End of table without finding it
  185.     je      clrret                  ; Then return from interrupt
  186.     mov     al,3                    ; Select RR3A
  187.     out     dx,al
  188.     jmp     short d6        ; Delay
  189. d6:     jmp     short d7
  190. d7:     jmp     short d8
  191. d8:     in      al,dx
  192.     test    al,al                   ; Test if a nonzero IP here
  193.     jnz     sccip                   ; Yes, handle it
  194.     inc     si                      ; No, next A CTRL
  195.     inc     si
  196.     jmp     sccpoll
  197.  
  198. ; Read SCC interrupt vector from RR2B, it should always be correct
  199. ; Extract channel number and status from vector. Determine handler address.
  200.  
  201. sccip:  mov     dx,[si]                 ; Read B CTRL address
  202.     mov     al,2                    ; Select RR2B
  203.     out     dx,al
  204.     jmp     short d9        ; Delay
  205. d9:     jmp     short d10
  206. d10:    jmp     short d11
  207. d11:    in      al,dx           ; Read the vector
  208.     mov     bl,al                   ; Copy vector (need it later for status)
  209.     shr     bl,1                    ; Discard least significant bit
  210.     and     bx,7ch                  ; Isolate channel number (and make word)
  211.     xor     bl,04h                  ; Toggle A/B channel bit
  212. ifdef   LARGEDATA
  213.     les si,Sccchan[bx]
  214. else
  215.     shr     bl,1                    ; Discard another bit (Sccchan=words)
  216.     mov     si,Sccchan[bx]          ; Read address of channel structure
  217. endif
  218. ifdef   LARGEDATA               ; Test for NULL
  219.     push    ax
  220.     mov             ax,es
  221.     test    ax,ax
  222.     pop             ax
  223.     jne nn1
  224. endif
  225.     test    si,si                   ; Test for NULL
  226.     je      clrret                  ; No channel struct, ignore it
  227. nn1:
  228.     and     ax,06h                  ; Isolate status info from vector
  229.     add     ax,ax                   ; Make index in FAR PTR array
  230.     mov     bx,ax                   ; It must be in BX
  231.  
  232. ; Call the handler (defined in C), with Sccchan struct as a parameter
  233.  
  234.     push    es
  235.     push    si                      ; Put channel struct as a parameter
  236. ifdef   LARGEDATA
  237.     call    dword ptr es:[bx+si]    ; Call the handler
  238. else
  239.     call    dword ptr [bx+si]       ; Call the handler
  240. endif
  241.     pop     si                      ; Remove parameter from stack
  242.     pop     es
  243.  
  244. ; Check for more interrupt pending bits
  245.  
  246.     jmp     sccintnv
  247.  
  248. ;       sccnovec        endproc
  249.  
  250.     end
  251.